/*
 * @Author: xiaosihan
 * @Date: 2025-01-15 22:11:03
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2025-01-17 20:36:24
 */
// SphereMesh.ts

import effectMaterial1 from "@views/materials/effectMaterial1";
import { Clock, DoubleSide, Texture, TextureLoader } from "three";
import {
  BackSide,
  BufferAttribute,
  Camera,
  FrontSide,
  Group,
  Mesh,
  MeshBasicMaterial,
  SphereGeometry,
} from "three";
import uv2PNG from "./uv2.png";

export default class SphereMesh extends Group {
  constructor() {
    super();
  }

  clock = new Clock();

  sphereGeo = (() => {
    const sphereGeo = new SphereGeometry(0.5, 100, 100, 0, Math.PI);
    const position = sphereGeo.getAttribute("position");
    const uv = new Float32Array(position.count * 2);
    for (let i = 0; i < position.count; i++) {
      const x = position.getX(i);
      const y = position.getY(i);
      const z = position.getZ(i);
      uv[i * 2] = x + 0.5;
      uv[i * 2 + 1] = y + 0.5;
    }
    sphereGeo.setAttribute("uv", new BufferAttribute(uv, 2));
    sphereGeo.rotateX(Math.PI / -2);
    return sphereGeo;
  })();

  //特效着色器1
  frontSphereMesh = (() => {
    // const frontMaterial1 = effectMaterial1.clone();
    // frontMaterial1.side = DoubleSide;
    const frontSphereMesh = new Mesh(this.sphereGeo, effectMaterial1);
    // frontSphereMesh.onBeforeRender = (renderer) => {
    //   frontMaterial1.uniforms.time.value += this.clock.getDelta() * 10;
    // };
    this.add(frontSphereMesh);
    return frontSphereMesh;
  })();
}
